<!DOCTYPE html>
<html>
  <head>
    <title>test.html</title>
	<meta charset="utf-8">
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    
    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="js/jquery.form.js"></script>
    <script type="text/javascript" src="js/jquery.base64.js"></script>
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
  
  <body>
  isbn:<input type="text" name="getISBN" />
  <a href="" onclick="chaxun()">查询</a>
  
  
  
    <form action="" method="post" id="_form" name="_form" enctype="multipart/form-data" >
        <input type="file" name="bookFile" id="file" />     
        <input type="button" onclick="onsub()" value="上传" />
	</form>
    <input type="button" onClick="excelOut()" value="导出" />
    
    
    <form action="" method="post" id="userInfo" name="userInfo" enctype="multipart/form-data">
    	userId<input type="text" name="userId" />
    	username<input type="text" name="username" />
    	<input type="text" name="util" />
    	<input type="text" name="department" />
    	<input type="text" name="company" />
    	<input type="text" name="address" />
    	<input type="text" name="qq" />
    	<input type="text" name="wechat" />
    	<input type="text" name="email" />
    	<input type="text" name="mobile_phone" />
    	<input type="text" name="phone" />
    	<input type="text" name="sex" />
    	<input type="text" name="age" />
    	<input type="text" name="birthday" />
    	<input type="text" name="loanid" />
    	password<input type="text" name="password" />
    	<input type="text" name="password_1" />
    	<input type="text" name="level" />	
    	<input type="button" onclick="use()" value="userInfo" />
    </form>
    
	<form method="get" name="form1" action="http://opac.nlc.cn:80/F/RKXNAEU79AJ4TNQHAACINJ6KYB98X6AB5Y8V1H694TSRM8KXLH-09597" onsubmit="return presearch(this);"> 
		<select name="find_code" id="find_code"> 
	     <option value="WRD" selected="">所有字段</option> 
	     <option value="WTP">正题名</option> 
	     <option value="WTI">其它题名</option> 
	     <option value="WAU">著者</option> 
	     <option value="WSU">主题词</option> 
	     <option value="CLC">中图分类号</option> 
	     <option value="WSC">论文专业</option> 
	     <option value="WRS">论文研究方向</option> 
	     <option value="WDU">论文学位授予单位</option> 
	     <option value="WDD">论文学位授予时间</option> 
	     <option value="WPL">出版地</option> 
	     <option value="WPU">出版者</option> 
	     <option value="WSE">丛编</option> 
	     <option value="LOC">索取号</option> 
	     <option value="ISS">ISSN</option> 
	     <option value="ISB">ISBN</option> 
	     <option value="SRC">ISRC</option> 
	     <option value="BAR">条码号</option> 
	     <option value="SYS">系统号</option> 
	    </select> 
	    <input autocomplete="off" style="width:250px" name="request" value="" id="reqterm"  />
		
		<input id="local_base" type="radio" checked value="NLC01" name="local_base" checked="checked"/><span style="font-size:13px;" id=label>中文文献</span> 
		<input id="local_base" type="radio" value="NLC09" name="local_base"/><span style="font-size:13px;" id=label>外文文献</span> 
		<input id="all_base" type="radio" value="" name="local_base"/><span style="font-size:13px;" id=label>全部文献</span> 
	
	
		<input type="submit" style="/* position:absolute;top:25px;left:525px;z-index:1;width:165px;height:44px;background:url(http://opac.nlc.cn:80/exlibris/aleph/u20_1/alephe/www_f_chi/icon/btn.jpg) no-repeat;border:none; */" value="检索" /> 
	</form>   
    <form id="bookInfo" name="bookInfo" action="" method="post" enctype="multipart/form-data">
    	ISBN<input type="text" name="isbn" /><input type="button" onclick="getBookInfo()" value="查询" /><br/>
    	code<input type="text" name="code" /><br/>
    	正题名<input type="text" name="title" /><br/>
    	副题名<input type="text" name="subtitle" /><br/>
    	外文题名<input type="text" name="title_foreign" /><br/>
    	作者<input type="text" name="author" /><br/>
    	出版社<input type="text" name="publisher" /><br/>
    	出版地址<input type="text" name="pubaddress" /><br/>
    	出版年月<input type="text" name="pubdate" /><br/>
    	页数<input type="text" name="pages" /><br/>
    	尺寸<input type="text" name="size" /><br/>
    	主题词<input type="text" name="keyword" /><br/>
    	摘要<input type="text" name="summary" /><br/>
    	分类号<input type="text" name="category" /><br/>
    	正文语种<input type="text" name="language" /><br/>
    	定价<input type="text" name=price /><br/>
    	丛编名<input type="text" name="series_name" /><br/>
    	附件<input type="text" name="enclosure" /><br/>
    	CN刊号<input type="text" name="cn" /><br/>
    	出版周期<input type="text" name="period" /><br/>
    	主办单位<input type="text" name="unit" /><br/>
    	馆藏类别<input type="text" name="classification" /><br/>
    	装订样式<input type="text" name="binding" /><br/>
    	翻译者<input type="text" name="translator" /><br/>
    	
    	<input type="button" onclick="addBook()" value="新增图书" />
    	
    </form>
    
    <form id="adminInfo" name="adminInfo" action="" method="post" enctype="multipart/form-data">
    	管理员号<input type="text" name="userId" /><br/>
    	管理员姓名<input type="text" name="username" /><br/>
    	管理员密码<input type="text" name="password" /><br/>
    	确认密码<input type="text" name="password_1" /><br/>
    	管理员角色<input type="text" name="role" /><br/>
    	<input type="button" onclick="addAdmin()" value="新增管理员" />
    </form>
    
    <form id="login">
    	<input type="text" name="userId" />
    	<input type="text" name="password" />
    	<input type="button" onclick="tologin()" value="提交" />
    </form>
    
    <form id="changepass">
    	<input type="text" name="passwordOld" />
    	<input type="text" name="passwordNew" />
    	<input type="text" name="passwordNew_1" />
    	<input type="button" onclick="changepass()" value="修改密码" />
    </form>
    <input type="button" value="getAllOverdue" onclick="getAllOverdue()" />
    
  </body>
  
  <script type="text/javascript">
  	
  	
  	function getAllOverdue() {
  		var path = "http://115.29.37.191:8080/Library/library/bookLend/OverRecord";
  		$.ajax({
  			type : "GET",
  			url : path,
  			success : function(data, status) {
  				console.log(data);
  				localStorage.admin = data.admin.idadmin;
  			}
  		});
  	}
  	
  	
  	var userid = "qwe"
  	
	function changepass() {
		
		var pass = $('input[name="passwordNew"]').val();
  		var pass1 = $('input[name="passwordNew_1"]').val();
		
		if (pass == pass1) {
			var path = "http://115.29.37.191:8080/Library/library/admin/changePass/" + userid;
	  		$.ajax({
	  			type : "POST",
	  			url : path,
	  			data : $('#changepass').serialize(),
	  			success : function(data, status) {
	  				console.log(data);
	  			}
	  		});
		}
		
	}  	
  	
  	function tologin() {
  		var path = "http://localhost:8080/Library/library/admin/login";
  		$.ajax({
  			type : "POST",
  			url : path,
  			data : $('#login').serialize(),
  			success : function(data, status) {
  				console.log(data);
  				localStorage.admin = data.admin.idadmin;
  			}
  		});
  	}
  	
  	
  	function addAdmin() {
  		
  		var pass = $('input[name="password"]').val();
  		var pass1 = $('input[name="password_1"]').val();
  		
  		if (pass == pass1) {
			var path = "http://localhost:8080/Library/library/admin/insertAAdmin/admin";
	  		document.adminInfo.action = path;
	  		$('#adminInfo').submit();
		}
  		
  	}
  	
  	function getBookInfo() {
  		var isbn = $('input[name="isbn"]').val();
  		//var isbn = "9787509766446";
  		var path = "https://api.douban.com/v2/book/isbn/:" + isbn ;
  		$.ajax({
  			type : "GET",
  			url : path,
  			dataType : "jsonp",
  			success : function(data, status) {
  				console.log(data);
  				$('input[name="author"]').attr('value', data.author[0]);
  				$('input[name="title"]').attr('value', data.title);
  				$('input[name="binding"]').attr('value', data.binding);
  				$('input[name="idnumber"]').attr('value', data.id);
  				$('input[name="title_foreign"]').attr('value', data.origin_title);
  				$('input[name="pages"]').attr('value', data.pages);
  				$('input[name="price"]').attr('value', data.price);
  				$('input[name="pubdate"]').attr('value', data.pubdate);
  				$('input[name="publisher"]').attr('value', data.publisher);
  				$('input[name="subtitle"]').attr('value', data.subtitle);
  				$('input[name="summary"]').attr('value', data.summary);
  				$('input[name="translator"]').attr('value', data.translator[0]);
  				$('input[name="unit"]').attr('value', data.unit);
  			},
  			error : function(a, b, c){
  				console.log(c);
  			}
  		});
  	}
  	
  	function addBook() {
  		var path = "http://115.29.37.191:8080/Library/library/book/insertABook/" + localStorage.admin;
  		document.bookInfo.action = path;
  		$('#bookInfo').submit();
  	}
  	
  	function use(){
  		var path = "http://115.29.37.191:8080/Library/library/admin/insertAUser/admin";
  		document.userInfo.action = path;
  		$('#userInfo').submit();
  	}
  	
  	
  	function excelOut(){
  		$.ajax({
  			type : "GET",
  			url : "http://115.29.37.191:8080/Library/library/test/selectAll",
  			success : function(data, status){
  				console.log(data);
  				getExcelData(data);
  			},
  			error : function(a, b, c){
  				alert(c);
  			}
  		});
  	}
  	
  	
  	function onsub(){
  	
  		var path = "http://115.29.37.191:8080/Library/library/book/excelInsert/" + localStorage.admin;
  		$('#_form').attr('action', path);
  		$('#_form').submit();
  	
  	}
  	
  	$(document).ready(function(){  
    	$('#_form').ajaxForm({  
        	dataType: 'json',
        	success: processJson 
    	});
    
    	function processJson(data){  
    		console.log(data);
    		//var jsoStr = JSON.stringify(data); //将JSON对象转化为JSON字符
	       	/* if(data.statusCode=="200"){
	       		$("#progressbar").css("width","100%");
	         		layer.msg("导入成功",{time:1500},function(){
	            	window.location.reload();
	        	});
	       	}
	       	else{
	       		layer.msg(statusCode(data.statusCode),{time:1500});
	       	} */
	       	
    	}
});


	function getExcelData(excelData){
		// 另一个model
		var tableHtml = "<tr><td>序号</td><td>姓名</td><td>添加时间</td></tr>";
		$.each(excelData.list, function(n, value){
			tableHtml += "<td>" 
				+ (n+1) +"</td><td>"
				+ value.name +"</td><td>"
				+ value.addTime.year + "_" + (value.addTime.month+1) + "_" + value.addTime.day +"</td></tr>";
		});

		var sheetName = "111";
		formattable(tableHtml,sheetName);
	}

	function formattable(tableHtml, sheetName) {
		var template = '<html xmlns:o="urn:schemas-microsoft-com:office:office"'+
		' xmlns:x="urn:schemas-microsoft-com:office:excel" '+
		'xmlns="http://www.w3.org/TR/REC-html40"><head>'+
		'<!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>'+
		'<x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/>'+
		'</x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook>'+
		'</xml><![endif]--><meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8"/>'+
		'</head><body><table>{table}</table></body></html>';
		var ctx = {
			worksheet : name,
			table : tableHtml
		};
		var downloadLink = document.createElement("a");
		downloadLink.href = 'data:application/vnd.ms-excel;base64,'
				+ base64(format(template, ctx));
		downloadLink.download = sheetName + ".xls";
		document.body.appendChild(downloadLink);
		downloadLink.click();
		document.body.removeChild(downloadLink); 
	}
		function base64(s) {
		//alert(s);
		return $.base64.btoa(unescape(encodeURIComponent(s)));
	}
	
	var format = function(s, c) {
		return s.replace(/{(\w+)}/g, function(m, p) {
			return c[p];
		});
	}

  </script>
  
</html>
